package com.ibuu.demos.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ibuu.demos.pojo.News;
import com.ibuu.demos.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/news")
public class NewsController {

    @Autowired
    private NewsService newsService;

    @GetMapping("/getnews")
    public List<News> getNews() {
        Page<News> newsPage = newsService.getNews();
        return newsPage.getRecords();
    }

    @PostMapping("/publish")
    public String publishNews(@RequestBody News news) {
        String s = newsService.publishNews(news);
        return s;
    }
    @DeleteMapping("/delete/{id}")
    public String deleteNews(@PathVariable("id") Integer id){
        newsService.removeById(id);
        return "success";
    }
}
